<template>
    <view>
        <emptyList v-if="data.list.length == 0" :empty_list_title="!is_search?'该地区暂时没有商家':(search_value?'搜不到，换个关键字试试吧':'搜一搜商家名、商家介绍')"></emptyList>
        <view v-for="(info, key) in data.list" :key="key" :class="[info.open_item !== false ? '' : 'grayscale']" class="flex padding-20 bg-white margin-14 radius-16"
            @tap="()=> {
                info.user_id > 0 ?
                $store.commit('userNavTo', '/seller/item/list?seller_id='+info.user_id) :
                $store.commit('userNavTo', '/seller/item/list?true_seller_id='+info.seller_id+'&sa_id='+info.sa_id)
            }">
            <view class="margin-right-10 flex-g1">
                <image class="radius-10" style="width: 150rpx; height:150rpx;" :src="info.logo | ossUrl(150)"></image>
            </view>
            <view class="width-100p margin-left-4 flex-g1">
                <view class="text-15 text-000 text-bold text-cut-1 line-height-11em">{{info.name}}</view>
                <view class="cu-capsule margin-top-10" v-if="info.open_item === false">
                    <view class='cu-tag bg-nddyny'>
                        营业时间
                    </view>
                    <view class="cu-tag line-nddyny">
                        {{info.open_start_time | timeFormat('hh:mm')}} -
                        {{info.open_end_time | timeFormat('hh:mm')}}
                    </view>
                </view>
                <view v-if="info.remark" class="text-999 text-sm text-cut-2 margin-top-10 line-height-11em">{{info.remark}}</view>
                <view class="text-sm margin-top-10 flex justify-between line-height-11em">
                    <view class="text-nddyny">
                        金券赠送比例 {{info.gold_coupon_ratio}}%
                    </view>
                    <view class="text-999">
                        {{info.area_distance | m2km}}
                    </view>
                </view>
                <view class="flex margin-top-10">
                    <view v-if="info.is_express == 0 && info.is_same_city == 0 && info.is_to_shop == 0" class="cu-tag bg-nddyny light sm">
                        当面支付
                    </view>
                    <view v-if="info.is_express == 1" class="cu-tag bg-nddyny sm">全国邮寄</view>
                    <view v-if="info.is_same_city > 0" class="cu-tag bg-nddyny sm">同城配送</view>
                    <view v-if="info.is_to_shop == 1" class="cu-tag bg-nddyny sm">到店自取</view>
                </view>
                <view class="flex margin-top-14" v-if="info.item_list && info.item_list.length > 0" @tap.stop="()=>{}">
                    <view v-for="(item_info, ckey) in info.item_list" :key="ckey" style="width: 172rpx;" @tap="$store.commit('userNavTo', '/seller/item/list?seller_id='+info.user_id+'&buy_mode=0&item_id='+item_info.item_id)">
                        <view>
                            <image mode="aspectFill" class="radius-10" style="width: 160rpx; height:120rpx;" :src="item_info.logo | ossUrl(160)"></image>
                        </view>
                        <view class="line-height-11em text-cut-1 text-11 margin-top-6">
                            {{item_info.name}}
                        </view>
                        <view class="line-height-11em text-gray text-cut" style="width: 170rpx;">
                            <text class="text-xs text-red">￥</text>
                            <text class="text-13 text-red">{{item_info.price | floor}}</text>
                            <text class="text-xs text-through text-gray padding-left-4" v-if="item_info.oprice > 0">
                                ￥{{item_info.oprice | floor}}
                            </text>
                        </view>
                    </view>
                </view>
            </view>
        </view>
        <footRight v-if="!is_search" class="margin-bottom-100" :tapRefresh="()=>{getList($api.list_action_force_init)}"></footRight>
    </view>
</template>

<script>
    import footRight from '@/components/nddyny/common/footRight.vue';
    export default {
        components: {
            footRight,
        },
        props: ['data_append', 'is_search'],
        data() {
            let data = {
                offset: 0,
                limit: 15,
                stop: false,
                list: [],
            };
            return {
                search_value: null,
                data_bak: this.$nddyny.object.copy(data),
                data: this.$nddyny.object.copy(data),
            }
        },
        methods: {
            initData() {
                this.search_value = null;
                this.$set(this, 'data', this.$nddyny.object.copy(this.data_bak));
            },
            refreshList() {
                this.getList(this.$api.list_action_force_init);
            },
            getList(action, search_value) {
                this.search_value = search_value;
                if (!(this.data_append.form.area_lng > 0 && this.data_append.form.area_lat > 0)) {
                    this.$store.commit('userToastNone', '没定位');
                    return;
                }
                let data_append = this.$nddyny.object.copy(this.data_append.form);
                if (search_value) {
                    data_append['search_value'] = search_value;
                }
                this.$api.list(this, {
                    action,
                    data_append,
                    url: '/seller/info/list',
                    success: (Result, data_key) => {
                        if (this.$api.form.toast(this, Result, data_key)) return;
                        let current_time = this.$nddyny.date.format(new Date(), 'hhmm');
                        Result.result.list.forEach(info => {
                            if (info.open_item !== true && info.open_item !== false) {
                                if (
                                    (info.open_start_time == 0 && info.open_end_time == 0) ||
                                    (current_time * 1 >= info.open_start_time * 1 && current_time *
                                        1 <= info.open_end_time * 1)
                                ) {
                                    info.open_item = true;
                                } else {
                                    info.open_item = false;
                                }
                            }
                        });
                        this.$set(this.data, 'list', this.data.list.concat(Result.result.list));
                    }
                });
            }
        }
    }
</script>
